﻿using Microsoft.EntityFrameworkCore;

namespace Application.Data
{
    public class JobManagerDbContext : DbContext
    {
        //public JobManagerDbContext()
        //{
        //}
        //AddDbContext(options)
        public JobManagerDbContext(DbContextOptions<JobManagerDbContext> options)
            : base(options)
        {
        }

        #region JobTask
        public virtual DbSet<JobTask> JobTask { get; set; }
        public virtual DbSet<JobTaskRecord> JobTaskRecord { get; set; }
        public virtual DbSet<KeyValue> KeyValue { get; set; }
        public virtual DbSet<OperationQueue> OperationQueue { get; set; }
        #endregion

        #region other
        public virtual DbSet<Passive> Passive { get; set; }
        #endregion

        #region Sys
        public virtual DbSet<SysManager> SysManager { get; set; }
        public virtual DbSet<SysLogOperation> SysLogOperation { get; set; }
        //public virtual DbSet<DistributedLocks> DistributedLocks { get; set; }
        public virtual DbSet<Notice> Notice { get; set; }
        #endregion

        protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
        {

        }

        protected override void OnModelCreating(ModelBuilder modelBuilder)
        {
            #region 逻辑删除过滤
            //system
            modelBuilder.Entity<SysManager>().HasQueryFilter(s => !s.IsDelete);
            modelBuilder.Entity<SysLogOperation>().HasQueryFilter(s => !s.IsDelete).HasAnnotation("StorageEngine", "MyISAM");
            //JobTask
            modelBuilder.Entity<JobTask>().HasQueryFilter(s => !s.IsDelete);
            modelBuilder.Entity<JobTaskRecord>().HasQueryFilter(s => !s.IsDelete);
            modelBuilder.Entity<KeyValue>().HasQueryFilter(s => !s.IsDelete);
            modelBuilder.Entity<Passive>().HasQueryFilter(s => !s.IsDelete);
            #endregion


        }
    }
}
